package crm.salesOrderProcessing.managedbean;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.event.ActionEvent;
import java.util.List;
import java.io.Serializable;
import javax.faces.bean.ViewScoped;
import crm.salesOrderProcessing.entity.SalesQuotationEntity;
import crm.salesOrderProcessing.session.SalesQuotationSessionBean;
import java.text.ParseException;

@ManagedBean
@ViewScoped
public class DeleteSalesQuotationManagedBean implements Serializable{
  
   public Long id;  
    @EJB
    SalesQuotationSessionBean salesQuotationSessionBean;
    private SalesQuotationEntity selectedQuotation;
    private SalesQuotationEntity temp;
  
    public DeleteSalesQuotationManagedBean() {
       selectedQuotation =new SalesQuotationEntity();
    }
    
    public SalesQuotationEntity getSelectedQuotation() {  
         //System.out.print("!!!!!!!!!!!!!!!!!!!"+selectedQuotation.getId());
       return selectedQuotation;  
    }  
    public void setSelectedQuotation(SalesQuotationEntity selectedQuotation) {  
        this.selectedQuotation = selectedQuotation;  
    } 
  
    
//      public void viewQuotation(ActionEvent event) throws IOException{
//        SalesQuotationEntity sq=(SalesQuotationEntity)event.getComponent().getAttributes().get("viewQuotation");
//        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("newQuotation", selectedQuotation);
//        FacesContext.getCurrentInstance().getExternalContext().redirect("viewSalesInquiry.xhtml");
//    }
  

    public List<SalesQuotationEntity> getSalesQuotations() {
        return salesQuotationSessionBean.getAllSalesQuotation();
    }
    
    public void viewProcessing(ActionEvent event){
        //setSelectedQuotation((SalesQuotationEntity)event.getComponent().getAttributes().get("ViewQuotation"));
        setTemp((SalesQuotationEntity)event.getComponent().getAttributes().get("ViewQuotation"));
        // System.out.print("******************"+getSelectedQuotation().getCompany().getName());
       
    }

    public void deleteSalesQuotation(ActionEvent event) throws ParseException{
       id=(Long)event.getComponent().getAttributes().get("deleteQuotation");
       salesQuotationSessionBean.deleteSalesQuotation(id);
     //  selectedQuotation = new SalesQuotationEntity();
    }
       
//       public void saveChanges(ActionEvent event)
//    {
//        
//        companySessionBean.saveChanges(selectedCompany);
//        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Changes saved.", ""));        
//    }

    public SalesQuotationEntity getTemp() {
        
        return temp;
    }

    public void setTemp(SalesQuotationEntity temp) {
        this.temp = temp;
    }
}
